/*
 * @file     g_chgrin.h
 * @brief    This file contains all the functions prototypes for the CHGRIN firmware library.
 *
 * Change Logs:
 * Date            Author             Version        Notes
 * 2021-05-25      dengzhiqian        V1.0.0         the first version
 */
#ifndef __G_CHGRIN_H
#define __G_CHGRIN_H

#ifdef __cplusplus
extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "g_1903.h"
#include "g_system.h"
#include "g_bpu.h"
#include "g_otp.h"

/** @defgroup chgrin event select
 * @{
 */
#define EVENT0_CHGR_STATE_VBAT_LV               BIT0
#define EVENT1_CHGR_STATE_RCH_EN                BIT1
#define EVENT2_CHGR_STATE_IND                   BIT2
#define EVENT3_CHGR_STATE_ICHG                  BIT3
#define EVENT4_CHGR_RESET                       BIT4
#define EVENT5_CHGR_UVLO_OK_AON                 BIT5
#define EVENT6_CHGR_PGOOD                       BIT6
#define EVENT7_CHGR_DPPM_OV_CV                  BIT7
#define EVENT8_CHGR_DPPM_OV_CC                  BIT8
#define EVENT9_CHGR_CC_OV_CV                    BIT9
#define EVENT10_CHGR_IN_DET_AON                 BIT10
#define EVENT11_VBAT_OV_FLAG                    BIT11
#define EVENT12_POWER_KEY                       BIT12
#define EVENT_ALL                               (0x1fff)


#define IS_CHGR_EVENT_SELECT(EVENT)    (EVENT <= EVENT_ALL)

/**
 * @brief  interrupt type select
 */
typedef enum
{
    CHGR_LOW_LEVEL = 0,
    CHGR_HIGH_LEVEL

} CHGR_Event_IrqTypeDef;

#define IS_TYRE_SELECT(TYRE)    (((TYRE) == CHGR_LOW_LEVEL)       || \
                                ((TYRE)  == CHGR_HIGH_LEVEL))

/**
 * @brief  power supply type select
 */
typedef enum
{
    POWER_CHGR_IN = 0,
    POWER_VBAT
} CHARG_SystemPowerSource;

/**
 * @brief  set charging current
 */
typedef enum
{
    CHARG_CURRENT_40MA = 0,
    CHARG_CURRENT_60MA,
    CHARG_CURRENT_80MA,
    CHARG_CURRENT_100MA,
    CHARG_CURRENT_120MA,
    CHARG_CURRENT_140MA,
    CHARG_CURRENT_160MA,
    CHARG_CURRENT_180MA,
    CHARG_CURRENT_200MA,
    CHARG_CURRENT_220MA,
    CHARG_CURRENT_240MA,
    CHARG_CURRENT_260MA,
    CHARG_CURRENT_280MA,
    CHARG_CURRENT_300MA,
    CHARG_CURRENT_320MA,
    CHARG_CURRENT_340MA
} CHARG_Current;

typedef enum
{
    OVERVOLTAGE_3782MV = 0,
    OVERVOLTAGE_3835MV,
    OVERVOLTAGE_3888MV,
    OVERVOLTAGE_3941MV ,
    OVERVOLTAGE_3994MV,
    OVERVOLTAGE_4047MV,
    OVERVOLTAGE_4100MV,
    OVERVOLTAGE_4153MV,
    OVERVOLTAGE_4200MV,
    OVERVOLTAGE_4253MV,
    OVERVOLTAGE_4306MV,
    OVERVOLTAGE_4359MV ,
    OVERVOLTAGE_4412MV,
    OVERVOLTAGE_4465MV,
    OVERVOLTAGE_4518MV,
    OVERVOLTAGE_4571MV 
} CHARG_OverVoltage;
typedef enum
{
    STARTVOLTAGE_3676MV = 0,
    STARTVOLTAGE_3729MV,
    STARTVOLTAGE_3782MV,
    STARTVOLTAGE_3835MV,
    STARTVOLTAGE_3888MV,
    STARTVOLTAGE_3941MV,
    STARTVOLTAGE_3994MV,
    STARTVOLTAGE_4047MV,
    STARTVOLTAGE_4100MV,
    STARTVOLTAGE_4153MV,
    STARTVOLTAGE_4206MV,
    STARTVOLTAGE_4259MV,
    STARTVOLTAGE_4312MV,
    STARTVOLTAGE_4365MV,
    STARTVOLTAGE_4418MV,
    STARTVOLTAGE_4471MV
} CHARG_StartVoltage;
typedef enum 
{
    TRICKLE_CURRENT_10 = 0,
    TRICKLE_CURRENT_20,
    TRICKLE_CURRENT_30,
    TRICKLE_CURRENT_40
} CHARGE_TRICKLE_GRADIENT;

/**
 * @brief  event dectect select
 */
typedef enum
{
    CHGR_EVENT0 = 0,
    CHGR_EVENT1,
    CHGR_EVENT_ALL
} CHGR_Event_DecEnDef;

#define IS_DECTECT_EN_SELECT(EVENT)    (((EVENT) == CHGR_EVENT0)       || \
                                        ((EVENT) == CHGR_EVENT1)       || \
                                        ((EVENT)  == CHGR_EVENT_ALL))

void G_CHGR_Event_Detect_En(CHGR_Event_DecEnDef Chgr_Event,G_FunctionalState NewState);
void G_CHGR_Irq_En(G_FunctionalState NewState);
void G_CHGR_Event_En(uint32_t Chgr_Event,G_FunctionalState NewState);
void G_CHGR_Event_Irq_Type(uint32_t Chgr_Event,CHGR_Event_IrqTypeDef Irq_Type);
void G_CHGR_Event_Clear_Irq(uint32_t Chgr_Event);
uint32_t G_CHGR_Event_Get_Irq_State(void);
void G_CHARGE_CurSel(CHARG_Current ChargCurtSel);
void G_CHARGE_SystemPowerSelect(CHARG_SystemPowerSource powerSource);
G_Boolean G_CHARGE_InsertDet(void);
G_Boolean G_CHARGE_State(void);

void G_CHARGE_CutOffVolSel(CHARG_OverVoltage ChargOutVol);
void G_CHARGE_RechargeVolSel(CHARG_StartVoltage ChargOutVol);

void G_CHARGE_TrickleCurrent( CHARGE_TRICKLE_GRADIENT Trickle_Gradient );
void G_CHARGE_TerminationCurrent( CHARGE_TRICKLE_GRADIENT Trickle_Gradient );
void G_CHARGE_ForceOffChargerBias(G_FunctionalState NewState);
void G_CHARGE_ForceOffChargerCCAndCV(G_FunctionalState NewState);
void G_CHARGE_ForceOffChargerPassTransistor(G_FunctionalState NewState);
void G_CHARGE_ForceCCModeConfig(G_FunctionalState NewState);
void G_CHARGE_ForceCCAndCVLoop(G_FunctionalState NewState);
void G_CHARGE_ForceCVMode(G_FunctionalState NewState);
void G_CHARGE_InputSinkCurrent(G_FunctionalState NewState);
void G_CHARGE_ForceSwitch(G_FunctionalState NewState);
#ifdef __cplusplus
}
#endif

#endif /*__G_CHGRIN_H*/

/************************ (C) COPYRIGHT GKT *****END OF FILE****/
